<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}银川科技学院自行车管理系统 - 管理后台{% endblock %}</title>
    {% load static %}
    <link href="{% static 'bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'bootstrap-icons/bootstrap-icons.css' %}" rel="stylesheet">
    <style>
        .sidebar {
            min-height: 100vh;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.8);
            border-radius: 0.5rem;
            margin: 0.25rem 0;
        }
        .sidebar .nav-link:hover,
        .sidebar .nav-link.active {
            color: white;
            background-color: rgba(255, 255, 255, 0.1);
        }
        .main-content {
            background-color: #f8f9fa;
            min-height: 100vh;
        }
        .card {
            border: none;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
        }
        .stats-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        .stats-card .card-body {
            padding: 1.5rem;
        }
        .stats-number {
            font-size: 2rem;
            font-weight: bold;
        }
        .table th {
            background-color: #f8f9fa;
            border-top: none;
        }
        .badge {
            font-size: 0.75em;
        }
        .navbar-brand {
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <nav class="col-md-3 col-lg-2 d-md-block sidebar collapse">
                <div class="position-sticky pt-3">
                    <div class="text-center mb-4">
                        <h6 class="text-white">
                            银川科技学院自行车管理系统
                        </h6>
                        {% if user.is_authenticated %}
                        <p class="text-white-50 small">
                            {% if user.collegeuser %}
                                {{ user.collegeuser.get_college_display }}
                            {% endif %}
                        </p>
                        {% endif %}
                    </div>
                    
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'admin_dashboard' %}active{% endif %}" 
                               href="{% url 'bike:admin_dashboard' %}">
                                <i class="bi bi-speedometer2"></i> 仪表盘
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'admin_bike_list' %}active{% endif %}" 
                               href="{% url 'bike:admin_bike_list' %}">
                                <i class="bi bi-list-ul"></i> 自行车管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'admin_bike_add' %}active{% endif %}" 
                               href="{% url 'bike:admin_bike_add' %}">
                                <i class="bi bi-plus-circle"></i> 添加自行车
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'violation_list' %}active{% endif %}" 
                               href="{% url 'bike:violation_list' %}">
                                <i class="bi bi-exclamation-triangle"></i> 违章记录
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'secret_key_management' %}active{% endif %}" 
                               href="{% url 'bike:secret_key_management' %}">
                                <i class="bi bi-key"></i> 管理秘钥
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'export_qr_codes' %}active{% endif %}" 
                               href="{% url 'bike:export_qr_codes' %}">
                                <i class="bi bi-download"></i> 导出二维码
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'bike:admin_bike_list' %}">
                                <i class="bi bi-arrow-clockwise"></i> 刷新二维码
                            </a>
                        </li>
                        {% if college_user.is_super_admin %}
                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'user_management' %}active{% endif %}" 
                               href="{% url 'bike:user_management' %}">
                                <i class="bi bi-people"></i> 用户管理
                            </a>
                        </li>
                        {% endif %}
                        <li class="nav-item mt-3">
                            <a class="nav-link" href="{% url 'bike:home' %}">
                                <i class="bi bi-eye"></i> 查看前台
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'bike:admin_logout' %}">
                                <i class="bi bi-box-arrow-right"></i> 退出登录
                            </a>
                        </li>
                    </ul>
                </div>
            </nav>

            <!-- 主内容区域 -->
            <main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 main-content">
                <!-- 顶部导航栏 -->
                <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                    <h1 class="h2">{% block page_title %}管理后台{% endblock %}</h1>
                    <div class="btn-toolbar mb-2 mb-md-0">
                        <div class="btn-group me-2">
                            {% if user.is_authenticated %}
                            <span class="badge bg-primary">
                                <i class="bi bi-person"></i> {{ user.username }}
                            </span>
                            {% endif %}
                        </div>
                    </div>
                </div>

                <!-- 消息提示 -->
                {% if messages %}
                <div class="row">
                    <div class="col-12">
                        {% for message in messages %}
                        <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                            {{ message }}
                            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                        </div>
                        {% endfor %}
                    </div>
                </div>
                {% endif %}

                <!-- 页面内容 -->
                {% block content %}
                {% endblock %}
            </main>
        </div>
    </div>

    <script src="{% static 'bootstrap/js/bootstrap.bundle.min.js' %}"></script>
    {% block extra_js %}
    {% endblock %}
</body>
</html>
